package com.ruoyi.property.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.property.domain.FeeDiscountInfo;
import com.ruoyi.property.service.IFeeDiscountInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 折扣设置Controller
 * 
 * @author sux
 * @date 2021-06-30
 */
@Controller
@RequestMapping("/property/feeDiscountInfo")
public class FeeDiscountInfoController extends BaseController {
    private String prefix = "property/feeDiscountInfo";

    @Autowired
    private IFeeDiscountInfoService feeDiscountInfoService;

    @RequiresPermissions("property:feeDiscountInfo:view")
    @GetMapping()
    public String feeDiscountInfo()
    {
        return prefix + "/feeDiscountInfo";
    }

    /**
     * 查询折扣设置列表
     */
    @RequiresPermissions("property:feeDiscountInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FeeDiscountInfo feeDiscountInfo)
    {
        startPage();
        List<FeeDiscountInfo> list = feeDiscountInfoService.selectFeeDiscountInfoList(feeDiscountInfo);
        return getDataTable(list);
    }

    /**
     * 导出折扣设置列表
     */
    @RequiresPermissions("property:feeDiscountInfo:export")
    @Log(title = "折扣设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FeeDiscountInfo feeDiscountInfo)
    {
        List<FeeDiscountInfo> list = feeDiscountInfoService.selectFeeDiscountInfoList(feeDiscountInfo);
        ExcelUtil<FeeDiscountInfo> util = new ExcelUtil<FeeDiscountInfo>(FeeDiscountInfo.class);
        return util.exportExcel(list, "feeDiscountInfo");
    }

    /**
     * 新增折扣设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存折扣设置
     */
    @RequiresPermissions("property:feeDiscountInfo:add")
    @Log(title = "折扣设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FeeDiscountInfo feeDiscountInfo)
    {
        return toAjax(feeDiscountInfoService.insertFeeDiscountInfo(feeDiscountInfo));
    }

    /**
     * 修改折扣设置
     */
    @GetMapping("/edit/{discountId}")
    public String edit(@PathVariable("discountId") Long discountId, ModelMap mmap)
    {
        FeeDiscountInfo feeDiscountInfo = feeDiscountInfoService.selectFeeDiscountInfoById(discountId);
        mmap.put("feeDiscountInfo", feeDiscountInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存折扣设置
     */
    @RequiresPermissions("property:feeDiscountInfo:edit")
    @Log(title = "折扣设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FeeDiscountInfo feeDiscountInfo)
    {
        return toAjax(feeDiscountInfoService.updateFeeDiscountInfo(feeDiscountInfo));
    }

    /**
     * 删除折扣设置
     */
    @RequiresPermissions("property:feeDiscountInfo:remove")
    @Log(title = "折扣设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(feeDiscountInfoService.deleteFeeDiscountInfoByIds(ids));
    }
}
